package com.roseski.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.roseski.dto.ThemeReq;
import com.roseski.dto.ThemeResp;
import com.roseski.model.RoseskiTheme;
import com.roseski.service.ThemeService;

@RestController
@RequestMapping(value = "order/theme")
public class ThemeController {
	
	@Autowired
	ThemeService themeService;
	
	@RequestMapping(value="listRecommendTheme")
	@ResponseBody
	public Map<String, List<ThemeResp>> listRecommendTheme(ThemeReq req){
		Map<String, List<ThemeResp>> map = new HashMap<>();
		List<RoseskiTheme>  list = themeService.queryRecommendThemeList();
		List<ThemeResp> resp = new ArrayList<ThemeResp>();
		for(RoseskiTheme theme : list) {
			ThemeResp themeResp = new ThemeResp();
			themeResp.setCardThemeId(theme.getThemeId());
			themeResp.setCardThemeImgUrls(Arrays.asList(theme.getImgUrlList().split(";")));
			if("TRUE".equals(theme.getBannerFlag())) {
				themeResp.setIsTopping(1);
			}else {
				themeResp.setIsTopping(0);
			}
			themeResp.setCardThemeTitle(theme.getThemeName());
			resp.add(themeResp);
		}
		map.put("themeList", resp);
		return map;
	}
}
